package rsj.interceptor;

import com.rlyy.aibase.utils.base.Box;
import common.util.validator.ParameterConversionCheck;
import rsj.interceptor.export.IExportParamCheck;
import rsj.interceptor.export.ReportParam;

import javax.validation.groups.Default;
import java.util.HashMap;
import java.util.Map;

/**
 * 转发导出
 *
 * @author yuanqinglong
 * @since 2021/8/3 16:00
 */
public abstract class AbstractForwardExport {


    /**
     * 导出的url
     */
    protected static final Map<String, IExportParamCheck> EXPORT_CHECK = new HashMap<>();

    public static final  String TASK_LIST_KEY = "rsj|export|task";

    static {
        EXPORT_CHECK.put("rsj_report_account_export", (param, type, checkGroup) -> ParameterConversionCheck.parameterConversionCheckFastFail(param, type, Default.class));
        EXPORT_CHECK.put("rsj_report_account_detail_export", (param, type, checkGroup) -> ParameterConversionCheck.parameterConversionCheckFastFail(param,
                type, ReportParam.AutKeyid.class, Default.class));
        EXPORT_CHECK.put("rsj_report_account_download_log", (param, type, checkGroup) -> ParameterConversionCheck.parameterConversionCheckFastFail(param,
                type, ReportParam.AutKeyid.class, Default.class));



        EXPORT_CHECK.put("rsj_report_account_product_export", (param, type, checkGroup) -> ParameterConversionCheck.parameterConversionCheckFastFail(param, type, Default.class));
        EXPORT_CHECK.put("rsj_report_account_product_detail_export", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type, Default.class, ReportParam.ProdUid.class, ReportParam.AutKeyid.class));
        EXPORT_CHECK.put("rsj_report_account_product_download_log", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type, ReportParam.AutKeyid.class, ReportParam.ProdUid.class, Default.class));




        EXPORT_CHECK.put("rsj_report_customer_export", (param, type, checkGroup) -> ParameterConversionCheck.parameterConversionCheckFastFail(param, type, Default.class));
        EXPORT_CHECK.put("rsj_report_customer_detail_export", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type, ReportParam.CustId.class, Default.class));
        EXPORT_CHECK.put("rsj_report_customer_download_log", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type, ReportParam.CustId.class, Default.class));




        EXPORT_CHECK.put("rsj_report_customer_product_export", (param, type, checkGroup) -> ParameterConversionCheck.parameterConversionCheckFastFail(param, type, Default.class));
        EXPORT_CHECK.put("rsj_report_customer_product_detail_export", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type, ReportParam.CustId.class, ReportParam.ProdUid.class, Default.class));
        EXPORT_CHECK.put("rsj_report_customer_product_download_log", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type, ReportParam.CustId.class, ReportParam.ProdUid.class, Default.class));



        EXPORT_CHECK.put("rsj_report_product_export", (param, type, checkGroup) -> ParameterConversionCheck.parameterConversionCheckFastFail(param, type));
        EXPORT_CHECK.put("rsj_report_product_detail_export", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type, Default.class, ReportParam.ProdUid.class));
        EXPORT_CHECK.put("rsj_report_product_download_log", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type, ReportParam.ProdUid.class, Default.class));



        EXPORT_CHECK.put("rsj_report_product_category_export", (param, type, checkGroup) -> ParameterConversionCheck.parameterConversionCheckFastFail(param, type));
        EXPORT_CHECK.put("rsj_report_product_category_detail_export", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param, type,ReportParam.ProdType.class, Default.class));
        EXPORT_CHECK.put("rsj_report_product_category_download_log", (param, type, checkGroup) ->
                ParameterConversionCheck.parameterConversionCheckFastFail(param,type, ReportParam.ProdType.class, Default.class));


    }

    /**
     * 是导出操作
     *
     * @param param 参数
     * @return boolean
     */
    public static boolean isExport(Box param) {
        return EXPORT_CHECK.containsKey(param.getApi());
    }


    /**
     * 远期出口
     * 转发导出请求
     *
     * @param param 参数
     * @return {@link Box}
     * @throws Exception 异常
     */
    public abstract Box forwardExport(Box param) throws Exception;
}
